package com.ruoyi.learn.java.algorithm.dp;

import java.util.Arrays;

public class LianXuZhengShuHe {

    public static void main(String[] args) {

        int[][] data = new int[][]{{1, 2, -1, 2}, {1, 2, -1, 2, 3, -2, 3, 1}};
        for (int i = 0; i < data.length; i++) {
            System.out.println("连续整型数组" + Arrays.toString(data[i]));
            System.out.println("答案" + maxValue1(data[i]));

        }
    }


    public static int maxValue1(int[] data) {
        if (data.length == 1) {
            return data[0];
        }
        int max = data[0];
        int globaleMax = data[0];
        for(int i = 1;i < data.length;i ++){
            max = Math.max(data[i],max + data[i]);
            globaleMax = Math.max(globaleMax,max);
        }
        return globaleMax;
    }

    public static int maxValue(int[] data) {
        if (data.length == 1) {
            return data[0];
        }
        int[] data1 = Arrays.copyOf(data, data.length - 1);
        int max = Math.max(maxValue(data1), maxValue(data1) + data[data.length - 1]);
        return max;
    }



}